package net.cassandraview.db;

import org.apache.cassandra.thrift.KeyRange;
import org.apache.cassandra.thrift.SlicePredicate;
import org.apache.cassandra.thrift.SliceRange;

import java.nio.ByteBuffer;

/**
 * User: nagakhl
 * Date: 21.01.12
 * Time: 21:54
 */
public class Condition {

    private SlicePredicate predicate;
    
    private KeyRange range;

    public Condition() {
        this.predicate = getDefaultPredicate();
        this.range = getDefaultRange();
    }

    public Condition(SlicePredicate predicate) {
        this.predicate = predicate;
        this.range = getDefaultRange();
    }

    public Condition(SlicePredicate predicate, KeyRange range) {
        this.predicate = predicate;
        this.range = range;
    }

    protected SlicePredicate getDefaultPredicate() {
        SlicePredicate predicate = new SlicePredicate();
        SliceRange sliceRange = new SliceRange();
        sliceRange.setStart(new byte[0]).setFinish(new byte[0]);
        sliceRange.setCount(Integer.MAX_VALUE);
        predicate.setSlice_range(sliceRange);
        return predicate;
    }

    protected KeyRange getDefaultRange() {
        KeyRange range = new KeyRange();
        ByteBuffer startKey = ByteBuffer.wrap(new byte[0]);
        ByteBuffer endKey = ByteBuffer.wrap(new byte[0]);
        range.setStart_key(startKey).setEnd_key(endKey);
        return range;
    }

    public SlicePredicate getPredicate() {
        return predicate;
    }

    public void setPredicate(SlicePredicate predicate) {
        this.predicate = predicate;
    }

    public KeyRange getRange() {
        return range;
    }

    public void setRange(KeyRange range) {
        this.range = range;
    }
}
